/*     */ package com.zimbra.cs.db;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import java.sql.PreparedStatement;
/*     */ import java.sql.ResultSet;
/*     */ import java.sql.SQLException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class DbSession
/*     */ {
/*     */   private static final String CN_ID = "id";
/*     */   private static final String CN_SERVER_ID = "server_id";
/*     */   
/*     */   public static void create(DbPool.DbConnection conn, int id, String server_id)
/*     */     throws ServiceException
/*     */   {
/*  40 */     PreparedStatement stmt = null;
/*     */     try {
/*  42 */       stmt = conn.prepareStatement("INSERT INTO current_sessions (id, server_id) VALUES (?, ?)");
/*     */       
/*  44 */       int pos = 1;
/*  45 */       stmt.setInt(pos++, id);
/*  46 */       stmt.setString(pos++, server_id);
/*  47 */       stmt.executeUpdate();
/*     */     } catch (SQLException e) {
/*  49 */       if (!Db.errorMatches(e, Db.Error.DUPLICATE_ROW))
/*     */       {
/*     */ 
/*  52 */         throw ServiceException.FAILURE("inserting new session " + id + "," + "server_id", e);
/*     */       }
/*     */     } finally {
/*  55 */       DbPool.closeStatement(stmt);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static boolean delete(DbPool.DbConnection conn, int id, String serverId)
/*     */     throws ServiceException
/*     */   {
/*  67 */     PreparedStatement stmt = null;
/*     */     try {
/*  69 */       stmt = conn.prepareStatement("DELETE FROM current_sessions WHERE id=? AND server_id = ?");
/*  70 */       int pos = 1;
/*  71 */       stmt.setInt(pos++, id);
/*  72 */       stmt.setString(pos++, serverId);
/*  73 */       stmt.executeUpdate();
/*  74 */       return true;
/*     */     } catch (SQLException e) {
/*  76 */       throw ServiceException.FAILURE("deleting session entry: " + id, e);
/*     */     } finally {
/*  78 */       DbPool.closeStatement(stmt);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static boolean deleteAll(DbPool.DbConnection conn)
/*     */     throws ServiceException
/*     */   {
/*  90 */     PreparedStatement stmt = null;
/*     */     try {
/*  92 */       stmt = conn.prepareStatement("DELETE FROM current_sessions");
/*  93 */       stmt.executeUpdate();
/*  94 */       return true;
/*     */     } catch (SQLException e) {
/*  96 */       throw ServiceException.FAILURE("deleting session entries: ", e);
/*     */     } finally {
/*  98 */       DbPool.closeStatement(stmt);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   public static List<String> get(DbPool.DbConnection conn, int id)
/*     */     throws ServiceException
/*     */   {
/* 106 */     PreparedStatement stmt = null;
/* 107 */     ResultSet rs = null;
/* 108 */     List<String> list = new ArrayList();
/*     */     try {
/* 110 */       stmt = conn.prepareStatement("SELECT server_id FROM current_sessions WHERE id = ?");
/* 111 */       stmt.setInt(1, id);
/* 112 */       rs = stmt.executeQuery();
/* 113 */       while (rs.next()) {
/* 114 */         list.add(rs.getString("server_id"));
/*     */       }
/*     */     } catch (SQLException e) {
/* 117 */       throw ServiceException.FAILURE("getting mailbox entry: " + id, e);
/*     */     } finally {
/* 119 */       DbPool.closeResults(rs);
/* 120 */       DbPool.closeStatement(stmt);
/*     */     }
/* 122 */     return list;
/*     */   }
/*     */   
/*     */   public static void deleteSessions(DbPool.DbConnection conn, String serverId) throws ServiceException {
/* 126 */     PreparedStatement stmt = null;
/*     */     try {
/* 128 */       stmt = conn.prepareStatement("DELETE FROM current_sessions where server_id = ?");
/* 129 */       stmt.setString(1, serverId);
/* 130 */       stmt.executeUpdate();
/*     */     } catch (SQLException e) {
/* 132 */       throw ServiceException.FAILURE("deleting session entries for server_id: " + serverId, e);
/*     */     } finally {
/* 134 */       DbPool.closeStatement(stmt);
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/db/DbSession.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */